import paho.mqtt.client as mqtt
import config_py


# 连接服务器回调
def on_connect(client, userdata, flags, rc):
    print("与服务器连接" + str(rc))
    # 订阅主题
    client.subscribe(config_py.mqtt_topic)
    client.subscribe('$SYS/brokers/+/clients/+/connected')
    client.subscribe('$SYS/brokers/+/clients/+/disconnected')
    client.subscribe(config_py.mqtt_response_topic)

# 收到消息回调
def on_message(client, userdata, msg):
    print("mqtt客户端接收数据:" + msg.topic + ":" + str(msg.payload) + str(get_time()))
    # 设备上线处理
    if '$SYS' in msg.topic:
        print()
    elif config_py.mqtt_response_topic in msg.topic:
        print('控制消息')
    else:
        print('普通消息')